﻿'Interface créer par Caroline St-Yves
'Programmez par Caroline St-Yves
'Modifié par Pierre-Luc Trottier (interets)
'Date de création : 5 septembre 2012, 8h00 am.
'Date dernière modification : 28 septembre 2012, 00:50 am.

Public Class FicheEmploye
    Dim oLocalContext As DBMainContext
    Dim localEmploye As Employe
    Dim localTypeEmp As Type_Employe
    Dim ajout As Boolean
    Dim modif As Boolean
    Dim lecture As Boolean

    Sub New()
        Me.New(New Employe)
        btnModifier.Image = My.Resources.Images.disk_blue
        Deverrouiller()
        ajout = True
        lecture = False
        localEmploye = New Employe
    End Sub

    Sub Deverrouiller()
        'Information personnelles

        txtNom.Enabled = True
        txtPrenom.Enabled = True
        dtpDateNaiss.Enabled = True
        txtNAS.Enabled = True
        txtAdresse.Enabled = True
        cboVille.Enabled = True
        cboProvince.Enabled = True
        cboPays.Enabled = True
        txtCodeP.Enabled = True
        txtTelMaison.Enabled = True
        txtTelBureau.Enabled = True
        txtPosteTel.Enabled = True
        txtCellulaire.Enabled = True
        txtCourriel.Enabled = True
        rbVehiculeOui.Enabled = True
        rbVehiculeNon.Enabled = True
        cboTypeVehicule.Enabled = True
        txtPermisConduire.Enabled = True
        txtSuccursale.Enabled = True
        txtTransit.Enabled = True
        txtFolio.Enabled = True
        rbHomme.Enabled = True
        rbFemme.Enabled = True
        pbPhotoEmp.Enabled = True
        btnAjoutImage.Enabled = True
        txtCommentaires.Enabled = True
        ckInactif.Enabled = True

        'Information(Professionnel)
        cboTypePoste.Enabled = True
        cboTypeEmp.Enabled = True
        dtpEmbauche.Enabled = True
        txtHeures.Enabled = True
        txtTaux.Enabled = True
        txtLogin.Enabled = True
        txtMDP.Enabled = True
        lbFormation.Enabled = True
        lbInteret.Enabled = True
        cboTypeVehicule.Enabled = True
        rbVehiculeNon.Enabled = True
        rbVehiculeOui.Enabled = True
        txtPermisConduire.Enabled = True


    End Sub
    Sub Verrouiller()
        'Information personnelles

        txtNom.Enabled = False
        txtPrenom.Enabled = False
        dtpDateNaiss.Enabled = False
        txtNAS.Enabled = False
        txtAdresse.Enabled = False
        cboVille.Enabled = False
        cboProvince.Enabled = False
        cboPays.Enabled = False
        txtCodeP.Enabled = False
        txtTelMaison.Enabled = False
        txtTelBureau.Enabled = False
        txtPosteTel.Enabled = False
        txtCellulaire.Enabled = False
        txtCourriel.Enabled = False
        rbVehiculeOui.Enabled = False
        rbVehiculeNon.Enabled = False
        cboTypeVehicule.Enabled = False
        txtPermisConduire.Enabled = False
        txtSuccursale.Enabled = False
        txtTransit.Enabled = False
        txtFolio.Enabled = False
        rbHomme.Enabled = False
        rbFemme.Enabled = False
        pbPhotoEmp.Enabled = False
        btnAjoutImage.Enabled = False
        txtCommentaires.Enabled = False
        ckInactif.Enabled = False

        'Information(Professionnel)
        cboTypePoste.Enabled = False
        cboTypeEmp.Enabled = False
        dtpEmbauche.Enabled = False
        txtHeures.Enabled = False
        txtTaux.Enabled = False
        txtLogin.Enabled = False
        txtMDP.Enabled = False
        lbFormation.Enabled = False
        lbInteret.Enabled = False
        cboTypeVehicule.Enabled = False
        rbVehiculeNon.Enabled = False
        rbVehiculeOui.Enabled = False
        txtPermisConduire.Enabled = False

    End Sub

    'Fonction pour ajouter les informations de l'employé de la base de données à la fenetre
    Sub New(ByVal oEmp As Employe)

        InitializeComponent()
        localEmploye = oEmp
        oLocalContext = New DBMainContext

        cboTypeEmp.DataSource = oLocalContext.Type_Employe
        cboTypeEmp.DisplayMember = "Nom_Type"
        cboTypePoste.DataSource = oLocalContext.Poste
        cboTypePoste.DisplayMember = "NomPoste"

        cboVille.Load()
        cboProvince.Load()
        cboPays.Load()


        initialisation()
        lecture = True
        Verrouiller()

    End Sub
    'initialisation des champs de la fenetre, à la BD
    Sub initialisation()
        dtpDateNaiss.MaxDate = Date.Today
        dtpEmbauche.MaxDate = Date.Today

        'Information Personnelles

        txtNom.Text = localEmploye.Nom
        txtPrenom.Text = localEmploye.Prenom

        'Date de naissance
        If localEmploye.DateNaissance Is Nothing Then
            dtpDateNaiss.Value = Date.Today
        Else
            dtpDateNaiss.Value = localEmploye.DateNaissance
        End If

        'NAS
        If localEmploye.NAS Is Nothing Then
            txtNAS.Text = ""
        Else
            txtNAS.Text = CStr(localEmploye.NAS)
        End If

        txtAdresse.Text = localEmploye.Adresse
        cboVille.Text = CStr(localEmploye.Ville)
        cboProvince.Text = localEmploye.Province
        cboPays.Text = localEmploye.Pays

        If cboPays.Text = "France" Then
            txtTelMaison.Mask = "00 00 00 00 00 00"
            txtTelBureau.Mask = "00 00 00 00 00 00"
            txtCellulaire.Mask = "00 00 00 00 00 00"
        ElseIf cboPays.Text = "Canada" Then
            txtTelMaison.Mask = "(000) 000-0000"
            txtTelBureau.Mask = "(000) 000-0000"
            txtCellulaire.Mask = "(000) 000-0000"
        End If

        txtCodeP.Text = localEmploye.Code_Postal
        txtTelMaison.Text = localEmploye.TelMaison
        txtTelBureau.Text = localEmploye.TelBureau
        txtPosteTel.Text = localEmploye.TelPoste
        txtCellulaire.Text = localEmploye.TelCellulaire
        txtCourriel.Text = localEmploye.Courriel
        cboTypeVehicule.SelectedItem = localEmploye.TypeVoiture
        txtPermisConduire.Text = localEmploye.NoPermiConduire

        'Succursale
        txtSuccursale.Text = If(IsNothing(localEmploye.Finance_Succursale), "", localEmploye.Finance_Succursale)

        'Transit
        If localEmploye.Finance_Transit Is Nothing Then
            txtTransit.Text = ""
        Else
            txtTransit.Text = CStr(localEmploye.Finance_Transit)
        End If

        'Folio
        If localEmploye.Finance_Folio Is Nothing Then
            txtFolio.Text = ""
        Else
            txtFolio.Text = CStr(localEmploye.Finance_Folio)
        End If

        txtCommentaires.Text = localEmploye.Note
        'Actif/Inactif

        If localEmploye.ID = 0 Then
            localEmploye.Actif = True
        End If
        If localEmploye.Actif = True Then
            ckInactif.Checked = False
            ckInactif.Image = My.Resources.Images.user1_delete
        ElseIf localEmploye.Actif = False Then
            ckInactif.Checked = True
            ckInactif.Image = My.Resources.Images.user1_back
        End If


        'Sexe
        If localEmploye.Sexe Is Nothing Then
            localEmploye.Sexe = "H"
        End If

        If localEmploye.Sexe = "H" Then
            rbHomme.Checked = True
        ElseIf localEmploye.Sexe = "F" Then
            rbFemme.Checked = True
        End If

        'Voiture
        If localEmploye.Voiture = False Then
            rbVehiculeNon.Checked = True
        ElseIf localEmploye.Voiture = True Then
            rbVehiculeOui.Checked = True
        End If


        'Information professionnelles

        cboTypePoste.SelectedItem = localEmploye.Poste
        cboTypeEmp.SelectedItem = localEmploye.Type_Employe


        'Date d'embauche
        If localEmploye.DateEmbauche Is Nothing Then
            dtpEmbauche.Value = Date.Today
        Else
            dtpEmbauche.Value = localEmploye.DateEmbauche
        End If

        'Nombre d'heures
        If localEmploye.NombreHre Is Nothing Then
            txtHeures.Text = ""
        Else
            txtHeures.Text = CStr(localEmploye.NombreHre)
        End If

        'Taux
        If localEmploye.Tx_Hor Is Nothing Then
            txtTaux.Text = 0
        Else
            txtTaux.Text = CStr(localEmploye.Tx_Hor)
        End If
        txtLogin.Text = localEmploye.Login
        txtMDP.Text = localEmploye.MotDePasse

        If Not localEmploye.ID = 0 Then
            lbInteret.DataSource = (From u In oLocalContext.Interet_Employe Join v In oLocalContext.Interet On u.ID_Interet Equals v.ID_Interet Where u.ID_Employe = localEmploye.ID Select v).ToList
            lbInteret.DisplayMember = "Nom"
        End If

        If Not localEmploye.ID = 0 Then
            lbFormation.DataSource = (From u In oLocalContext.Formation_Employe Join v In oLocalContext.Formation On u.ID_Formation Equals v.ID Where u.ID_Employe = localEmploye.ID Select v).ToList
            lbFormation.DisplayMember = "Nom"
        End If


        If Not localEmploye.Photo Is Nothing Then
            pbPhotoEmp.Image = Outils.GestionImage.GetImageFromDB(localEmploye.Photo)
            pbPhotoEmp.SizeMode = PictureBoxSizeMode.StretchImage
        Else
            pbPhotoEmp.Image = My.Resources.Images.NoPhoto_user
            pbPhotoEmp.SizeMode = PictureBoxSizeMode.StretchImage
        End If
    End Sub
    'Si l'employé possède un véhicule, les champs type et permis s'affiche, si l'employé ne possède pas de véhicule, ces champs-là se cachent.
    Private Sub rbVehiculeOui_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbVehiculeOui.CheckedChanged
        If rbVehiculeOui.Checked = True Then
            lblTypeVehicule.Show()
            lblPermis.Show()
            cboTypeVehicule.Show()
            txtPermisConduire.Show()
            lblNoteVehicule.Show()
            txtNoteVehicule.Show()
        ElseIf rbVehiculeNon.Checked = True Then
            lblTypeVehicule.Hide()
            lblPermis.Hide()
            cboTypeVehicule.Hide()
            txtPermisConduire.Hide()
            lblNoteVehicule.Hide()
            txtNoteVehicule.Hide()
        End If
    End Sub
    'Si le bouton modifier = Enregistrer alors on enregistre les informations inscrite dans la fenetre, dans la base de données.
    Private Sub btnModifier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModifier.Click

        If ajout = True Then
            If validation() = True Then

                With localEmploye
                    .Nom = txtNom.Text
                    .Prenom = txtPrenom.Text
                    .DateNaissance = dtpDateNaiss.Value
                    .NAS = txtNAS.Text
                    .Adresse = txtAdresse.Text
                    .Ville = cboVille.Text
                    .Province = cboProvince.Text
                    .Pays = cboPays.Text
                    .Code_Postal = txtCodeP.Text
                    .TelMaison = txtTelMaison.Text
                    .TelBureau = txtTelBureau.Text
                    .TelPoste = txtPosteTel.Text
                    .TelCellulaire = txtCellulaire.Text
                    .Courriel = txtCourriel.Text
                    .TypeVoiture = cboTypeVehicule.Text
                    .NoPermiConduire = txtPermisConduire.Text
                    .Finance_Succursale = CStr(txtSuccursale.Text)
                    .Finance_Transit = CStr(txtTransit.Text)
                    .Finance_Folio = CStr(txtFolio.Text)
                    .Note = txtCommentaires.Text
                    .Poste = CType(cboTypePoste.SelectedItem, Poste)
                    .Type_Employe = CType(cboTypeEmp.SelectedItem, Type_Employe)
                    .DateEmbauche = dtpEmbauche.Value
                    .NombreHre = txtHeures.Text
                    .Login = txtLogin.Text
                    .MotDePasse = txtMDP.Text
                    .Tx_Hor = txtTaux.Text

                    'Sexe
                    If localEmploye.Sexe Is Nothing Then
                        localEmploye.Sexe = "H"
                    End If

                    If rbHomme.Checked = True Then
                        localEmploye.Sexe = "H"
                    ElseIf rbFemme.Checked = True Then
                        localEmploye.Sexe = "F"
                    End If

                    'Véhicule
                    If rbVehiculeOui.Checked = True Then
                        .Voiture = True
                    ElseIf rbVehiculeNon.Checked = True Then
                        .Voiture = False
                    End If

                    'Actif/Inactif
                    ckInactif.Checked = False
                    If ckInactif.Checked = True Then
                        localEmploye.Actif = False
                    ElseIf ckInactif.Checked = False Then
                        localEmploye.Actif = True
                    End If
                End With

                oLocalContext.Employe.InsertOnSubmit(localEmploye)
                oLocalContext.CustomSubmitChanges()
                btnModifier.Image = My.Resources.Images.edit
                Verrouiller()
                ajout = False
                lecture = True
            End If

        ElseIf lecture = True Then
            Deverrouiller()
            btnModifier.Image = My.Resources.Images.disk_blue
            lecture = False
            modif = True

        ElseIf modif = True Then
            If validation() = True Then
                Dim oEmpModif As Employe
                oEmpModif = (From u In oLocalContext.Employe Where u.ID = localEmploye.ID Select u).FirstOrDefault

                With oEmpModif
                    .Nom = txtNom.Text
                    .Prenom = txtPrenom.Text
                    .DateNaissance = dtpDateNaiss.Value
                    .NAS = CInt(txtNAS.Text)
                    .Adresse = txtAdresse.Text
                    .Ville = cboVille.Text
                    .Province = cboProvince.Text
                    .Pays = cboPays.Text
                    .Code_Postal = txtCodeP.Text
                    .TelMaison = txtTelMaison.Text
                    .TelBureau = txtTelBureau.Text
                    .TelPoste = txtPosteTel.Text
                    .TelCellulaire = txtCellulaire.Text
                    .Courriel = txtCourriel.Text
                    .TypeVoiture = cboTypeVehicule.Text
                    .NoPermiConduire = txtPermisConduire.Text
                    .Finance_Succursale = CStr(txtSuccursale.Text)
                    .Finance_Transit = CStr(txtTransit.Text)
                    .Finance_Folio = CStr(txtFolio.Text)
                    .Note = txtCommentaires.Text
                    .Poste = CType(cboTypePoste.SelectedItem, Poste)
                    .Type_Employe = CType(cboTypeEmp.SelectedItem, Type_Employe)
                    .DateEmbauche = dtpEmbauche.Value
                    .NombreHre = txtHeures.Text
                    .Login = txtLogin.Text
                    .MotDePasse = txtMDP.Text
                    .Tx_Hor = txtTaux.Text

                    'Actif

                    If ckInactif.Checked = True Then
                        .Actif = False
                    ElseIf ckInactif.Checked = False Then
                        .Actif = True
                    End If

                    'Vehicule
                    If rbVehiculeOui.Checked = True Then
                        .Voiture = True
                    ElseIf rbVehiculeNon.Checked = True Then
                        .Voiture = False
                    End If

                    'Sexe
                    If rbHomme.Checked = True Then
                        .Sexe = "H"
                    ElseIf rbFemme.Checked = True Then
                        .Sexe = "F"
                    End If
                    .Photo = localEmploye.Photo

                End With

                oLocalContext.CustomSubmitChanges()
                modif = False
                Verrouiller()
                btnModifier.Image = My.Resources.Images.edit
                lecture = True
            End If
        End If
    End Sub

    Private Sub btnAjoutImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAjoutImage.Click
        Dim photoid As Integer
        Dim strPhoto As String

        strPhoto = Outils.GestionImage.GetImageFromFileDialog()
        photoid = Outils.GestionImage.SaveImageToDB(strPhoto)
        localEmploye.Photo = photoid
        pbPhotoEmp.Image = Outils.GestionImage.GetImageFromDB(photoid)
        pbPhotoEmp.SizeMode = PictureBoxSizeMode.StretchImage
    End Sub
    Function validation()
        Dim oValide As Boolean = True

        'Validation du nom
        If txtNom.Text.Trim = "" Then
            Outils.ErrorProviderFunctions.AddError(Me, txtNom, My.Resources.MessageErreur.DoitContenirUneValeur)
            oValide = False
        Else
            Outils.ErrorProviderFunctions.RemoveError(Me, txtNom)

            'Regex sur le nom
            If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.Nom, txtNom.Text) Then
                Outils.ErrorProviderFunctions.AddError(Me, txtNom, My.Resources.MessageErreur.ErreurNom)
                oValide = False
            Else
                Outils.ErrorProviderFunctions.RemoveError(Me, txtNom)
            End If
        End If

        'Validation du prénom

        If txtPrenom.Text.Trim = "" Then
            Outils.ErrorProviderFunctions.AddError(Me, txtPrenom, My.Resources.MessageErreur.DoitContenirUneValeur)
            oValide = False
        Else
            Outils.ErrorProviderFunctions.RemoveError(Me, txtPrenom)

            'Regex sur le prénom
            If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.Nom, txtPrenom.Text) Then
                Outils.ErrorProviderFunctions.AddError(Me, txtPrenom, My.Resources.MessageErreur.ErreurPrenom)
                oValide = False
            Else
                Outils.ErrorProviderFunctions.RemoveError(Me, txtPrenom)
            End If
        End If

        'Validation de l'adresse
        If txtAdresse.Text.Trim = "" Then
            Outils.ErrorProviderFunctions.AddError(Me, txtAdresse, My.Resources.MessageErreur.DoitContenirUneValeur)
            oValide = False
        Else
            Outils.ErrorProviderFunctions.RemoveError(Me, txtAdresse)

            'Regex de l'adresse
            If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.adresse, txtAdresse.Text) Then
                Outils.ErrorProviderFunctions.AddError(Me, txtAdresse, My.Resources.MessageErreur.ErreurAdresse)
                oValide = False
            Else
                Outils.ErrorProviderFunctions.RemoveError(Me, txtAdresse)
            End If
        End If

        'Validation sur le code postal du québec
        If cboPays.Text = "Canada" Then
            If txtCodeP.Text.Trim = "" Then
                Outils.ErrorProviderFunctions.AddError(Me, txtCodeP, My.Resources.MessageErreur.DoitContenirUneValeur)
                oValide = False
            Else
                Outils.ErrorProviderFunctions.RemoveError(Me, txtCodeP)

                ' Regex sur le code postal du québec
                If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.CodePostalQc, txtCodeP.Text) Then
                    Outils.ErrorProviderFunctions.AddError(Me, txtCodeP, My.Resources.MessageErreur.ErreurCodePostal)
                    oValide = False
                Else
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtCodeP)
                End If
            End If
        Else

            ''Validation sur le code postal de la france
            If cboPays.Text = "France" Then
                If txtCodeP.Text.Trim = "" Then
                    Outils.ErrorProviderFunctions.AddError(Me, txtCodeP, My.Resources.MessageErreur.DoitContenirUneValeur)
                    oValide = False
                Else
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtCodeP)

                    'Regex sur le code postal de la France
                    If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.CodePostalFr, txtCodeP.Text) Then
                        Outils.ErrorProviderFunctions.AddError(Me, txtCodeP, My.Resources.MessageErreur.ErreurCodePostalFr)
                        oValide = False
                    Else
                        Outils.ErrorProviderFunctions.RemoveError(Me, txtCodeP)
                    End If
                End If
            End If
        End If

        'Validation de la ville
        If cboVille.Text = "" Then
            Outils.ErrorProviderFunctions.AddError(Me, cboVille, My.Resources.MessageErreur.DoitContenirUneValeur)
            oValide = False
        Else
            Outils.ErrorProviderFunctions.RemoveError(Me, cboVille)
        End If

        'Validation de la province
        If cboProvince.Text = "" Then
            Outils.ErrorProviderFunctions.AddError(Me, cboProvince, My.Resources.MessageErreur.DoitContenirUneValeur)
            oValide = False
        Else
            Outils.ErrorProviderFunctions.RemoveError(Me, cboProvince)
        End If

        'Validation du pays
        If cboPays.Text = "" Then
            Outils.ErrorProviderFunctions.AddError(Me, cboPays, My.Resources.MessageErreur.DoitContenirUneValeur)
            oValide = False
        Else
            Outils.ErrorProviderFunctions.RemoveError(Me, cboPays)
        End If

        'Validation sur les numéros de téléphones du québec
        If cboPays.Text = "Canada" Then
            If Not (Not txtTelMaison.Text = "(   )    -" Or Not txtTelBureau.Text = "(   )    -" Or Not txtCellulaire.Text = "(   )    -") Then
                Outils.ErrorProviderFunctions.AddError(Me, txtTelMaison, My.Resources.MessageErreur.DoitContenirTelephone)
                Outils.ErrorProviderFunctions.AddError(Me, txtTelBureau, My.Resources.MessageErreur.DoitContenirTelephone)
                Outils.ErrorProviderFunctions.AddError(Me, txtCellulaire, My.Resources.MessageErreur.DoitContenirTelephone)
            Else
                Outils.ErrorProviderFunctions.RemoveError(Me, txtCellulaire)
                Outils.ErrorProviderFunctions.RemoveError(Me, txtTelMaison)
                Outils.ErrorProviderFunctions.RemoveError(Me, txtTelBureau)

                'Regex sur les numéros de téléphones du Québec

                If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.TelQuebec, txtTelMaison.Text) And Not txtTelMaison.Text = "(   )    -" Then
                    Outils.ErrorProviderFunctions.AddError(Me, txtTelMaison, My.Resources.MessageErreur.FormatTelQuebec)
                    oValide = False
                Else
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtTelMaison)
                End If

                If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.TelQuebec, txtTelBureau.Text) And Not txtTelBureau.Text = "(   )    -" Then
                    Outils.ErrorProviderFunctions.AddError(Me, txtTelBureau, My.Resources.MessageErreur.FormatTelQuebec)
                    oValide = False
                Else
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtTelBureau)
                End If

                If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.TelQuebec, txtCellulaire.Text) And Not txtCellulaire.Text = "(   )    -" Then
                    Outils.ErrorProviderFunctions.AddError(Me, txtCellulaire, My.Resources.MessageErreur.FormatTelQuebec)
                    oValide = False
                Else
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtCellulaire)
                End If

            End If

        ElseIf cboPays.Text = "France" Then

                If Not (Not txtTelMaison.Text = "(   )    -" Or Not txtTelBureau.Text = "(   )    -" Or Not txtCellulaire.Text = "(   )    -") Then
                    Outils.ErrorProviderFunctions.AddError(Me, txtTelMaison, My.Resources.MessageErreur.DoitContenirTelephone)
                    Outils.ErrorProviderFunctions.AddError(Me, txtTelBureau, My.Resources.MessageErreur.DoitContenirTelephone)
                    Outils.ErrorProviderFunctions.AddError(Me, txtCellulaire, My.Resources.MessageErreur.DoitContenirTelephone)
                Else
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtCellulaire)
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtTelMaison)
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtTelBureau)

                    'Regex sur les numéros de téléphones de la France

                    If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.TelFrance, txtTelMaison.Text) And Not txtTelMaison.Text = "(   )    -" Then
                        Outils.ErrorProviderFunctions.AddError(Me, txtTelMaison, My.Resources.MessageErreur.FormatTelFrance)
                    oValide = False
                Else
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtTelMaison)
                End If

                    If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.TelFrance, txtTelBureau.Text) And Not txtTelBureau.Text = "(   )    -" Then
                        Outils.ErrorProviderFunctions.AddError(Me, txtTelBureau, My.Resources.MessageErreur.FormatTelFrance)
                    oValide = False
                Else
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtTelBureau)
                End If

                    If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.TelFrance, txtCellulaire.Text) And Not txtCellulaire.Text = "(   )    -" Then
                        Outils.ErrorProviderFunctions.AddError(Me, txtCellulaire, My.Resources.MessageErreur.FormatTelFrance)
                    oValide = False
                Else
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtCellulaire)
                End If

                End If
            End If

        'Validation du NAS
            If txtNAS.Text = "" Then
                Outils.ErrorProviderFunctions.AddError(Me, txtNAS, My.Resources.MessageErreur.DoitContenirUneValeur)
                oValide = False
            Else
                Outils.ErrorProviderFunctions.RemoveError(Me, txtNAS)

                If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.NAS, txtNAS.Text) And Not txtNAS.Text = "(   )    -" Then
                    Outils.ErrorProviderFunctions.AddError(Me, txtNAS, My.Resources.MessageErreur.ErreurNAS)
                    oValide = False
                Else
                    Outils.ErrorProviderFunctions.RemoveError(Me, txtNAS)
                End If
            End If

        'Validation du courriel

        If txtCourriel.Text = "" Then
            Outils.ErrorProviderFunctions.AddError(Me, txtCourriel, My.Resources.MessageErreur.DoitContenirUneValeur)
            oValide = False
        Else
            Outils.ErrorProviderFunctions.RemoveError(Me, txtCourriel)

            If Not Outils.Validation.CheckRegex(Outils.Validation.TypeRegex.Courriel, txtCourriel.Text) And Not txtCourriel.Text = "(   )    -" Then
                Outils.ErrorProviderFunctions.AddError(Me, txtCourriel, My.Resources.MessageErreur.ErreurCourriel)
                oValide = False
            Else
                Outils.ErrorProviderFunctions.RemoveError(Me, txtCourriel)
            End If
        End If

        'Validation de la succursale
        If txtSuccursale.Text = "" Then
            Outils.ErrorProviderFunctions.AddError(Me, txtSuccursale, My.Resources.MessageErreur.DoitContenirUneValeur)
            oValide = False
        Else
            Outils.ErrorProviderFunctions.RemoveError(Me, txtSuccursale)
        End If

        'Validation du transit
        If txtTransit.Text = "" Then
            Outils.ErrorProviderFunctions.AddError(Me, txtTransit, My.Resources.MessageErreur.DoitContenirUneValeur)
            oValide = False
        Else
            Outils.ErrorProviderFunctions.RemoveError(Me, txtTransit)
        End If

        'Validation du folio
        If txtFolio.Text = "" Then
            Outils.ErrorProviderFunctions.AddError(Me, txtFolio, My.Resources.MessageErreur.DoitContenirUneValeur)
            oValide = False
        Else
            Outils.ErrorProviderFunctions.RemoveError(Me, txtFolio)
        End If


        'Validation
        If oValide = True Then
            Return True
        Else
            Return False
        End If
    End Function
    'Sub créé par Carolyne St-Yves, inspiré par Pierre-Luc Trottier

    Private Sub btnAjoutFormation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAjoutFormation.Click
        Dim oNewFormation As New GestionFormation()
        Dim oCustomMessagebox As New CustomMessageBox
        oNewFormation.btnSauvegarder.Visible = False
        oNewFormation.dgvFormation.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        oNewFormation.oListFormation = (From u In oLocalContext.Formation_Employe Join v In oLocalContext.Formation On u.ID_Formation Equals v.ID Where u.ID_Employe = localEmploye.ID Select v).ToList

        oCustomMessagebox.Height = oNewFormation.Height + 90
        oCustomMessagebox.Width = oNewFormation.Width
        oCustomMessagebox.Controls.Add(oNewFormation)
        oCustomMessagebox.ShowDialog()

        If oCustomMessagebox.DialogResult = DialogResult.OK Then
            localEmploye = (From u In oLocalContext.Employe Where u.ID = localEmploye.ID Select u).FirstOrDefault
            For Each item In oNewFormation.GetSelectedItems.ToArray
                If Not item Is Nothing Then
                    localEmploye.Formation_Employe.Add(New Formation_Employe With {.ID_Formation = item.ID})
                End If

            Next
            oLocalContext.CustomSubmitChanges()
            If Not localEmploye.ID = 0 Then
                lbFormation.DataSource = (From u In oLocalContext.Formation_Employe Join v In oLocalContext.Formation On u.ID_Formation Equals v.ID Where u.ID_Employe = localEmploye.ID Select v).ToList
                lbFormation.DisplayMember = "Nom"
            End If
        End If
    End Sub


    '<summary>
    ' Sub créé par Pierre-Luc Trottier
    ' pour l'ajour des intérets qui ne sont pas dans la liste.
    ' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnAjoutInteret_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAjoutInteret.Click
        Dim oNewForm As New GestionInterets()
        Dim oCustomMessageBox As New CustomMessageBox
        oNewForm.btnSauvegarder.Visible = False
        oNewForm.dgvInteret.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        oNewForm.oListInteretDejaDansLaListe = (From u In oLocalContext.Interet_Employe Join v In oLocalContext.Interet On u.ID_Interet Equals v.ID_Interet Where u.ID_Employe = localEmploye.ID Select v).ToList

        oCustomMessageBox.Height = oNewForm.Height + 90
        oCustomMessageBox.Width = oNewForm.Width
        oCustomMessageBox.Controls.Add(oNewForm)
        oCustomMessageBox.ShowDialog()

        If oCustomMessageBox.DialogResult = DialogResult.OK Then
            localEmploye = (From u In oLocalContext.Employe Where u.ID = localEmploye.ID Select u).FirstOrDefault
            For Each item In oNewForm.GetSelectedItems.ToArray
                If Not item Is Nothing Then
                    localEmploye.Interet_Employe.Add(New Interet_Employe With {.ID_Interet = item.ID_Interet})
                End If

            Next
            oLocalContext.CustomSubmitChanges()

            If Not localEmploye.ID = 0 Then
                lbInteret.DataSource = (From u In oLocalContext.Interet_Employe Join v In oLocalContext.Interet On u.ID_Interet Equals v.ID_Interet Where u.ID_Employe = localEmploye.ID Select v).ToList
                lbInteret.DisplayMember = "Nom"
            End If
        End If

    End Sub


    ''' <summary>
    ''' Sub créé par Pierre-Luc Trottier
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnSuppInteret_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuppInteret.Click
        Dim oInteret_Employe As Interet_Employe
        oInteret_Employe = (From u In oLocalContext.Interet_Employe Where u.ID_Employe = localEmploye.ID And u.ID_Interet = CType(lbInteret.SelectedItem, Interet).ID_Interet Select u).FirstOrDefault

        oLocalContext.Interet_Employe.DeleteOnSubmit(oInteret_Employe)
        oLocalContext.CustomSubmitChanges()

        If Not localEmploye.ID = 0 Then
            lbInteret.DataSource = (From u In oLocalContext.Interet_Employe Join v In oLocalContext.Interet On u.ID_Interet Equals v.ID_Interet Where u.ID_Employe = localEmploye.ID Select v).ToList
            lbInteret.DisplayMember = "Nom"
        End If

    End Sub
    'Sub créé par Carolyne St-Yves, inspiré par Pierre-Luc Trottier
    Private Sub btnSuppFormation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuppFormation.Click
        Dim oFormation_Employe As Formation_Employe
        oFormation_Employe = (From u In oLocalContext.Formation_Employe Where u.ID_Employe = localEmploye.ID And u.ID_Formation = CType(lbFormation.SelectedItem, Formation).ID Select u).FirstOrDefault

        oLocalContext.Formation_Employe.DeleteOnSubmit(oFormation_Employe)
        oLocalContext.CustomSubmitChanges()

        If Not localEmploye.ID = 0 Then
            lbFormation.DataSource = (From u In oLocalContext.Formation_Employe Join v In oLocalContext.Formation On u.ID_Formation Equals v.ID Where u.ID_Employe = localEmploye.ID Select v).ToList
            lbFormation.DisplayMember = "Nom"
        End If
    End Sub

    Private Sub cboPays_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboPays.TextChanged
        If cboPays.Text = "France" Then
            txtTelMaison.Mask = "00 00 00 00 00 00"
            txtTelBureau.Mask = "00 00 00 00 00 00"
            txtCellulaire.Mask = "00 00 00 00 00 00"
            txtCodeP.Mask = "00000"
            txtNAS.Mask = "000000000"

        ElseIf cboPays.Text = "Canada" Then
            txtTelMaison.Mask = "(000) 000-0000"
            txtTelBureau.Mask = "(000) 000-0000"
            txtCellulaire.Mask = "(000) 000-0000"
            txtCodeP.Mask = "A0A0A0"
            txtNAS.Mask = "000000000"
        End If
    End Sub

    Private Sub btnDispo_Click(sender As System.Object, e As System.EventArgs) Handles btnDispo.Click
        Dim oDispoEmp As New Disponibilite(oLocalContext, localEmploye)
        MainForm.AddTabToTC("Disponibilité/" + localEmploye.Nom + "," + localEmploye.Prenom, True, oDispoEmp)
    End Sub

    Private Sub FicheEmploye_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub ckInactif_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ckInactif.MouseDown
        Dim answer As DialogResult
        If ckInactif.Checked = True Then
            answer = MessageBox.Show("Voulez-vous vraiment activé cet employé ?", "Activation", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If answer = vbYes Then
                localEmploye.Actif = True
                ckInactif.Checked = False
                ckInactif.Image = My.Resources.Images.user1_delete
                oLocalContext.SubmitChanges()

            End If
        ElseIf ckInactif.Checked = False Then
            answer = MessageBox.Show("Voulez-vous vraiment désactivé cet employé ?", "Désactivation", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If answer = vbYes Then
                localEmploye.Actif = False
                ckInactif.Checked = True
                ckInactif.Image = My.Resources.Images.user1_back
            End If
        End If
    End Sub
End Class
